package com.gonsin.gview.common.controller;

import com.gonsin.base.ResponseResult;
import com.gonsin.gview.common.auth.WebApi;
import com.gonsin.gview.common.bean.UserMenuBean;
import com.gonsin.gview.common.po.MenuSearchPo;
import com.gonsin.gview.common.po.MenuSortPo;
import com.gonsin.gview.common.services.IMenusService;
import com.gonsin.gview.common.utils.SessionKeys;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@Api(tags = "菜单相关接口")
public class MenuController {

    @Autowired
    private IMenusService menusService;


    @ApiOperation("菜单 - 查询多个")
    @WebApi()
    @PostMapping(value = "/restapi/menus")
    public ResponseResult<List<UserMenuBean>> getAllMenus(
            @ApiIgnore HttpSession session, MenuSearchPo searchPo
    ) {
        String edificeKey = (String) session.getAttribute(SessionKeys.EDIFICE_KEY);
        return ResponseResult.result(menusService.getAllMenus(edificeKey, searchPo));
    }


    @ApiOperation("菜单 - 保存菜单顺序")
    @WebApi()
    @PutMapping(value = "/restapi/menus")
    public ResponseResult<List<UserMenuBean>> saveMenus(
            @ApiIgnore HttpSession session,
            @RequestBody MenuSortPo menuSortPo
    ) {
        String edificeKey = (String) session.getAttribute(SessionKeys.EDIFICE_KEY);
        return ResponseResult.result(menusService.saveMenus(edificeKey, menuSortPo));
    }

}
